package com.liveneo.adapter.mobile.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.liveneo.adapter.base.entity.PrpmUploadImage;
import com.liveneo.adapter.base.entity.PrpmUploadOcrImg;
import com.liveneo.adapter.base.entity.PrpmUploadVideo;
import com.liveneo.adapter.base.mapper.PrpmUploadImageMapper;
import com.liveneo.adapter.base.mapper.PrpmUploadOcrImgMapper;
import com.liveneo.adapter.base.mapper.PrpmUploadVideoMapper;
import com.liveneo.adapter.base.support.PageParam;
import com.liveneo.adapter.mobile.service.PrpmUploadService;

@Service
public class PrpmUploadServiceImpl implements PrpmUploadService {

    @Autowired
    private PrpmUploadImageMapper prpmUploadImageMapper;
    @Autowired
    private PrpmUploadVideoMapper prpmUploadVideoMapper;
    @Autowired
    private PrpmUploadOcrImgMapper prpmUploadOcrImgMapper;

    @Override
    public int prpmUpload(PrpmUploadImage prpmUploadImage, PrpmUploadVideo prpmUploadVideo) throws Exception {
        int r = 0;
        if (null != prpmUploadImage) {
            r = prpmUploadImageMapper.insert(prpmUploadImage);
        }

        if (null != prpmUploadVideo) {
            r = prpmUploadVideoMapper.insert(prpmUploadVideo);
        }

        return r;
    }

    @Override
    public int prpmUploadImage(PrpmUploadImage prpmUploadImage) throws Exception {

        return prpmUploadImageMapper.insert(prpmUploadImage);
    }

    @Override
    public int prpmUploadVideo(PrpmUploadVideo prpmUploadVideo) throws Exception {

        return prpmUploadVideoMapper.insert(prpmUploadVideo);
    }

    @Override
    public int saveUploadOcrImg(PrpmUploadOcrImg record) {
        return prpmUploadOcrImgMapper.insert(record);
    }

	/**
	  * @Title: updateUploadImageStayUploadById
	  * @Description: 
	  * @param @param prpmUploadImage
	  * @param @return 设定文件
	  * @return 返回类型
	  * @throws
	  */
	@Override
	public int updateUploadImageStayUploadById(PrpmUploadImage prpmUploadImage) {
		return prpmUploadImageMapper.updateByPrimaryKeySelective(prpmUploadImage);
	}

	/**
	  * @Title: updateUploadVideoeStayUploadById
	  * @Description: 
	  * @param @param prpmUploadVideo
	  * @param @return 设定文件
	  * @return 返回类型
	  * @throws
	  */
	@Override
	public int updateUploadVideoeStayUploadById(PrpmUploadVideo prpmUploadVideo) {
		return prpmUploadVideoMapper.updateByPrimaryKeySelective(prpmUploadVideo);
	}

	/**
	  * @Title: selectUploadImageStayUploadByCaseNo
	  * @Description: 
	  * @param @param caseNo
	  * @param @param stayUpload
	  * @param @return 设定文件
	  * @return 返回类型
	  * @throws
	  */
	@Override
	public List<PrpmUploadImage> selectImageStayUploadByCaseNoPage(String caseNo, String stayUpload,String lossItemId,String pageNum) {
		PageParam pageParam = new PageParam();
		pageParam.setPageNum(pageNum);
		pageParam.setPageSize(10);
		// 判断是否含有排序的字符串
        if (StringUtils.isNotBlank(pageParam.getOrderBy())) {
            PageHelper.orderBy(pageParam.getOrderBy());
        }
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        // 查询
        List<PrpmUploadImage> resultList = prpmUploadImageMapper.selectUploadImagePageList(caseNo, stayUpload,lossItemId);
		return resultList;
	}

	/**
	  * @Title: selectImageStayUploadByCaseNoList
	  * @Description: 
	  * @param @param caseNo
	  * @param @param stayUpload
	  * @param @return 设定文件
	  * @return 返回类型
	  * @throws
	  */
	@Override
	public List<PrpmUploadImage> selectImageStayUploadByCaseNoList(String caseNo, String stayUpload,String lossItemId) {
		return prpmUploadImageMapper.selectUploadImagePageList(caseNo, stayUpload,lossItemId);
	}

	/**
	  * @Title: selectVideoStayUploadByCaseNoPage
	  * @Description: 待上传视频数量
	  * @param @param caseNo
	  * @param @param stayUpload
	  * @param @param pageNum
	  * @param @return 设定文件
	  * @return 返回类型
	  * @throws
	  */
	@Override
	public List<PrpmUploadVideo> selectVideoStayUploadByCaseNoPage(String caseNo, String stayUpload,String lossItemId, String pageNum) {
		PageParam pageParam = new PageParam();
		pageParam.setPageNum(pageNum);
		pageParam.setPageSize(10);
		// 判断是否含有排序的字符串
        if (StringUtils.isNotBlank(pageParam.getOrderBy())) {
            PageHelper.orderBy(pageParam.getOrderBy());
        }
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        List<PrpmUploadVideo> resultList = prpmUploadVideoMapper.selectUploadVideoPageList(caseNo, stayUpload,lossItemId);
		return resultList;
	}

	/**
	  * @Title: selectVideoStayUploadByCaseNoList
	  * @Description: 待上传列表
	  * @param @param caseNo
	  * @param @param stayUpload
	  * @param @return 设定文件
	  * @return 返回类型
	  * @throws
	  */
	@Override
	public List<PrpmUploadVideo> selectVideoStayUploadByCaseNoList(String caseNo, String stayUpload,String lossItemId) {
		return prpmUploadVideoMapper.selectUploadVideoPageList(caseNo, stayUpload,lossItemId);
	}
}
